package com.example.kotlincoroutines.kotlin

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext

/**
 * withContext讲解
 */
@OptIn(ExperimentalStdlibApi::class)
fun main(){

    runBlocking(Dispatchers.IO) {
        println(coroutineContext.get(CoroutineDispatcher).toString())

        val res = withContext(Dispatchers.Default){
            delay(2000)
            println(coroutineContext.get(CoroutineDispatcher).toString())
            1
        }

        println(res)
        println(coroutineContext.get(CoroutineDispatcher).toString())
    }

}